/**
 * 
 */
package com.hand.cloud.b2b.daos.impl;

import de.hybris.platform.europe1.model.PriceRowModel;
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.servicelayer.search.FlexibleSearchService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hand.cloud.b2b.daos.PriceRowDAO;


/**
 * @author xuezezhan
 * @time 2014-9-2 下午2:02:44
 * 
 */
@Component(value = "priceRowDAO")
public class DefaultPriceRowDAO implements PriceRowDAO
{

	public static Logger LOG = Logger.getLogger(DefaultEPProductDAO.class);

	@Autowired
	private FlexibleSearchService flexibleSearchService;

	/**
	 * 通过货币单位和产品pk值获取一个价格
	 * 
	 * @return
	 */
	@Override
	public PriceRowModel getPriceRow(String currencycode, String pk)
	{
		StringBuffer queryStr = new StringBuffer("");
		queryStr.append("select {p.pk} ").append("from {pricerow as p join currency as c on {p.currency}={c.pk}}")
				.append("where {c.isocode}=?currencycode and {p.product}=?pk ");

		FlexibleSearchQuery query = new FlexibleSearchQuery(queryStr.toString());
		query.addQueryParameter("currencycode", currencycode);
		query.addQueryParameter("pk", pk);
		LOG.info("querystr:" + queryStr.toString());
		LOG.info("query:" + query);

		PriceRowModel priceRow = this.flexibleSearchService.searchUnique(query);
		return priceRow;
	}

}
